home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / GL / logo / logo.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  17KB  |  881 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /* logo.c
  18.  * Thant Tessman - July, '87
  19.  *
  20.  * (Three days and much ugly hacking.)
  21.  */
  22.  
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <math.h>
  26. #include <gl/gl.h>
  27. #include <gl/device.h>
  28. #include "light.h"
  29.  
  30. #define X 0
  31. #define Y 1
  32. #define Z 2
  33.  
  34. #define S_CYL 6.0
  35. #define D_CYL 8.0
  36. #define ELBOW_RAD 1.0
  37. #define JOINT 900
  38.  
  39. float radius, s_cyl, d_cyl, elbow_rad;
  40. int cres, bres;
  41. Angle joint;
  42. float mycirc[100][3];
  43. int num;
  44.  
  45. short dev, val;
  46. long gid;
  47.  
  48. float ident_matrix[4][4] = {
  49.     {1.0, 0.0, 0.0, 0.0},
  50.     {0.0, 1.0, 0.0, 0.0},
  51.     {0.0, 0.0, 1.0, 0.0},
  52.     {0.0, 0.0, 0.0, 1.0},
  53. };
  54.  
  55. float view[4][4] = {
  56.     {1.0, 0.0, 0.0, 0.0},
  57.     {0.0, 1.0, 0.0, 0.0},
  58.     {0.0, 0.0, 1.0, 0.0},
  59.     {0.0, 0.0, 0.0, 1.0},
  60. };
  61.  
  62. float tmp[4][4];
  63. short mx, my, omx, omy, nmx, nmy;
  64.  
  65. int bend_left(), bend_right(), bend_forward(), move_single(), move_double();
  66.  
  67. typedef struct polygon_struct {
  68.  
  69.     int n;
  70.  
  71.     float *polygon;    /* malloced 3 at a time */
  72.  
  73.     float *norm;    /* ditto */
  74.  
  75.     Colorindex *c;
  76.  
  77.     struct polygon_struct *next;
  78. } Poly;
  79.  
  80.  
  81. typedef struct thing_struct {
  82.  
  83.     Poly *polygons;
  84.  
  85.     int (*move)();
  86.  
  87.     struct thing_struct *sub;    /* sub things */
  88.  
  89.     struct thing_struct *next;    /* next (not affected by matrix) */
  90.  
  91. } Thing;
  92.  
  93.  
  94. Poly *new_polygon() {
  95.  
  96.     Poly *new;
  97.  
  98.     new = (Poly *)malloc(sizeof(Poly));
  99.  
  100.     new->n = 0;
  101.     new->polygon = NULL;
  102.     new->norm = NULL;
  103.     new->next = NULL;
  104.  
  105.     return(new);
  106. }
  107.  
  108.  
  109. Thing *new_thing() {
  110.  
  111.     int i, j;
  112.  
  113.     Thing *new;
  114.  
  115.     new = (Thing *)malloc(sizeof(Thing));
  116.  
  117.     new->sub = NULL;
  118.     new->next = NULL;
  119.  
  120.     return(new);
  121. }
  122.  
  123.  
  124. Thing *logo;
  125. Poly *elbow, *double_cylinder, *single_cylinder;
  126.  
  127.  
  128. int function=0;
  129. #define REORIENT 1
  130.  
  131. main (argc, argv)
  132. int    argc;
  133. char    *argv[];
  134. {
  135.     int needredraw = 1;
  136.     int i, j;
  137.  
  138.     initialize(argv[0]);
  139.  
  140.     while(TRUE) {
  141.  
  142.     while(qtest() || (function == 0 && joint == JOINT && needredraw == 0)) {
  143.         dev=qread(&val);
  144.         switch(dev) {
  145.         case ESCKEY :
  146.             if (!val) {
  147.                 gexit();
  148.                 exit(0);
  149.             }
  150.             break;
  151.         case LEFTMOUSE :
  152.             /*qread(&mx); qread(&my);*/
  153.             if (val) {
  154.             reset_values();
  155.  
  156.             for (i=0; i<4; i++) for (j=0; j<4; j++)
  157.                 view[i][j] = (float)(i==j);
  158.             }
  159.             break;
  160.         case MIDDLEMOUSE:
  161.             /*qread(&omx); qread(&omy);*/
  162.             if (val) {
  163.                 omx = getvaluator(MOUSEX);
  164.                 omy = getvaluator(MOUSEY);
  165.                 function = REORIENT;
  166.             }
  167.             else function = 0;
  168.             break;
  169.         case REDRAW:
  170.             reshapeviewport();
  171.             needredraw=1;
  172.             break;
  173.         }
  174.     }
  175.  
  176.     nmx = getvaluator(MOUSEX);
  177.     nmy = getvaluator(MOUSEY);
  178.  
  179.     switch(function) {
  180.  
  181.         case REORIENT:
  182.         reorient();
  183.         break;
  184.     }
  185.     omx=nmx; omy=nmy;
  186.  
  187.     draw_everything();
  188.     needredraw=0;
  189.     }
  190. }
  191.  
  192.  
  193. initialize(title)
  194. char *title;
  195. {
  196.     char tstr[1024];
  197.     char *t;
  198.     
  199.     t = strrchr(title, '/');
  200.     t = (t == NULL ? title : t+1);
  201.  
  202.     if (getgdesc(GD_BITS_NORM_DBL_RED) == 0)
  203.     {
  204.         sprintf(tstr,
  205.             "inform 'Your system must support double-buffered RGB mode to run %s'", t);
  206.         system(tstr);
  207.         exit(1);
  208.     }
  209.     if (getgdesc(GD_BITS_NORM_ZBUFFER) == 0)
  210.     {
  211.         sprintf(tstr,
  212.             "inform 'Your system must have a z-buffer to run %s'", t);
  213.         system(tstr);
  214.         exit(1);
  215.     }
  216.  
  217.     keepaspect(5, 4);
  218.  
  219.     gid=winopen(t);
  220.  
  221.     doublebuffer();
  222.     RGBmode();
  223.     gconfig();
  224.     subpixel(TRUE);
  225.     RGBcolor(0, 0, 0);
  226.     clear(); swapbuffers(); clear();
  227.     qdevice(INPUTCHANGE);
  228.     qdevice(REDRAW);
  229.     qdevice(ESCKEY);
  230.     qdevice(LEFTMOUSE);
  231.     qdevice(MIDDLEMOUSE);
  232.     /*tie(LEFTMOUSE, MOUSEX, MOUSEY);*/
  233.     /*tie(MIDDLEMOUSE, MOUSEX, MOUSEY);*/
  234.  
  235. /*    makerange(RAMPB, RAMPE, 50, 255, 0, 50, 50, 255); */
  236.  
  237.     reset_values();
  238.     zbuffer(TRUE);
  239.     zclear();
  240.     mmode(MVIEWING);
  241.     loadmatrix(ident_matrix);
  242.     init_lighting();
  243.  
  244.     build_logo();
  245.  
  246. }
  247.  
  248. draw_everything() {
  249.  
  250.     int i, j;
  251.     float t;
  252.  
  253.     if (joint>JOINT) {
  254.  
  255.     joint-=9;
  256.     t = (float)(1800-joint)/(float)(JOINT);
  257.     s_cyl = t * S_CYL;
  258.     d_cyl = t * D_CYL;
  259.     edit_parts();
  260.  
  261.     } else {
  262.  
  263.     joint = JOINT;
  264.  
  265.     }
  266.  
  267.     RGBcolor(0, 0, 0);
  268.     clear();
  269.     zclear();
  270.  
  271.     perspective(350, 5.0/4.0, 34, 72);
  272.  
  273.     mmode(MVIEWING);
  274.  
  275.     loadmatrix(ident_matrix);
  276.     lmbind(LIGHT0, OVER_LIGHT);
  277.     lmbind(LIGHT1, UNDER_LIGHT);
  278.  
  279.     lookat(-30.0, 30.0, 30.0, 0.0, 0.0, 0.0, 0);
  280.  
  281.     multmatrix(view);
  282.  
  283.     t = (2.0*radius + 2*d_cyl - s_cyl)/2.0;
  284.  
  285.     translate(t, -t, t);
  286.  
  287.     draw_thing(logo);
  288.  
  289.     swapbuffers();
  290. }
  291.  
  292.  
  293. build_logo() {
  294.  
  295.     int i;
  296.  
  297.     Thing *tmp;
  298.  
  299.     build_parts();
  300.  
  301.     logo = new_thing();
  302.  
  303.     for (i=0; i<3; i++) {
  304.  
  305.     if (i==0) {
  306.         tmp = logo;
  307.     } else {
  308.         tmp->sub = new_thing();
  309.         tmp=tmp->sub;
  310.     }
  311.  
  312.     tmp->polygons = double_cylinder;
  313.     tmp->move = move_double;
  314.  
  315.     tmp->sub = new_thing(); tmp = tmp->sub;
  316.     tmp->polygons = elbow;
  317.     tmp->move = bend_forward;
  318.  
  319.     tmp->sub = new_thing(); tmp = tmp->sub;
  320.     tmp->polygons = double_cylinder;
  321.     tmp->move = move_double;
  322.  
  323.     tmp->sub = new_thing(); tmp = tmp->sub;
  324.     tmp->polygons = elbow;
  325.     tmp->move = bend_forward;
  326.  
  327.     tmp->sub = new_thing(); tmp = tmp->sub;
  328.     tmp->polygons = single_cylinder;
  329.     tmp->move = move_single;
  330.  
  331.     tmp->sub = new_thing(); tmp = tmp->sub;
  332.     tmp->polygons = elbow;
  333.     tmp->move = bend_right;
  334.  
  335.  
  336.     tmp->sub = new_thing(); tmp = tmp->sub;
  337.     tmp->polygons = double_cylinder;
  338.     tmp->move = move_double;
  339.  
  340.     tmp->sub = new_thing(); tmp = tmp->sub;
  341.     tmp->polygons = elbow;
  342.     tmp->move = bend_forward;
  343.  
  344.     tmp->sub = new_thing(); tmp = tmp->sub;
  345.     tmp->polygons = double_cylinder;
  346.     tmp->move = move_double;
  347.  
  348.     tmp->sub = new_thing(); tmp = tmp->sub;
  349.     tmp->polygons = elbow;
  350.     tmp->move = bend_forward;
  351.  
  352.     tmp->sub = new_thing(); tmp = tmp->sub;
  353.     tmp->polygons = single_cylinder;
  354.     tmp->move = move_single;
  355.  
  356.     tmp->sub = new_thing(); tmp = tmp->sub;
  357.     tmp->polygons = elbow;
  358.     tmp->move = bend_left;
  359.     }
  360. }
  361.  
  362.  
  363. bend_right() {
  364.  
  365.     rotate(joint, 'z');
  366.     translate(0.0, elbow_rad, 0.0);
  367.     rotate(joint, 'x');
  368.     translate(0.0, -elbow_rad, 0.0);
  369.  
  370. }
  371.  
  372.  
  373. int bend_left() {
  374.  
  375.     rotate(-joint, 'z');
  376.     translate(0.0, elbow_rad, 0.0);
  377.     rotate(joint, 'x');
  378.     translate(0.0, -elbow_rad, 0.0);
  379.  
  380. }
  381.  
  382. bend_forward() {
  383.  
  384.     translate(0.0, elbow_rad, 0.0);
  385.     rotate(joint, 'x');
  386.     translate(0.0, -elbow_rad, 0.0);
  387.  
  388. }
  389.  
  390.  
  391. move_double() {
  392.  
  393.     translate(0.0, 0.0, -d_cyl);
  394. }
  395.  
  396. move_single() {
  397.  
  398.     translate(0.0, 0.0, -s_cyl);
  399. }
  400.  
  401.  
  402. reorient() {
  403.  
  404.  
  405.     pushmatrix();
  406.  
  407.     loadmatrix(ident_matrix);
  408.  
  409.     rotate((Angle) (nmx-omx), 'y');
  410.     rotate((Angle) (omy-nmy), 'x');
  411.  
  412.  
  413.     multmatrix(view);
  414.  
  415.     getmatrix(view);
  416.  
  417.     popmatrix();
  418.  
  419. }
  420.  
  421. print_matrix(m)
  422. float m[4][4];
  423. {
  424.     int i, j;
  425.  
  426.     for (i=0; i<4; i++) {
  427.  
  428.     for (j=0; j<4; j++) {
  429.  
  430.         printf("%8.4f  ", m[i][j]);
  431.     }
  432.     printf("\n");
  433.     }
  434.     printf("\n");
  435.  
  436. }
  437.  
  438. reset_values() {
  439.  
  440.     radius = 1.0;
  441.     s_cyl = 0.0;
  442.     d_cyl = 0.0;
  443.     elbow_rad = ELBOW_RAD;
  444.     cres = 8;
  445.     bres = 8;
  446.     joint = 1800;
  447. }
  448.  
  449.  
  450. draw_thing(thing)
  451. Thing *thing;
  452. {
  453.      while(thing) {
  454.  
  455.     (*thing->move)();
  456.  
  457.     draw_polygons(thing->polygons);
  458.  
  459.     draw_thing(thing->sub);
  460.  
  461.     thing = thing->next;
  462.      }
  463. }
  464.  
  465. draw_polygons(polygon)
  466. Poly *polygon;
  467. {
  468.     int i;
  469.  
  470.     lmbind(MATERIAL, MAT_LOGO);
  471.     lighting(TRUE);
  472.  
  473.     while(polygon=polygon->next) {
  474.     bgntmesh();
  475.     n3f(&polygon->norm[0*3]);
  476.     v3f(&polygon->polygon[0*3]);
  477.     n3f(&polygon->norm[1*3]);
  478.     v3f(&polygon->polygon[1*3]);
  479.     n3f(&polygon->norm[3*3]);
  480.     v3f(&polygon->polygon[3*3]);
  481.     n3f(&polygon->norm[2*3]);
  482.     v3f(&polygon->polygon[2*3]);
  483.     endtmesh();
  484.  
  485.     /*bgntmesh();
  486.     for (i=0; i<polygon->n; i++) {
  487.         n3f(&polygon->norm[i*3]);
  488.         v3f(&polygon->polygon[i*3]);
  489.     }
  490.     endtmesh();*/
  491.  
  492.     /*bgnclosedline();
  493.     for (i=0; i<polygon->n; i++) {
  494.         n3f(&polygon->norm[i*3]);
  495.         v3f(&polygon->polygon[i*3]);
  496.     }
  497.     endclosedline();*/
  498.  
  499. /*    poly(polygon->n, polygon->polygon);*/
  500. /*    splf(polygon->n, polygon->polygon, polygon->c);*/
  501.  
  502.     /* I'm only going to draw the first normal as a test case.  The rest are
  503.        really there (norm[3 * vertex_num])
  504.     */
  505.  
  506. /*    RGBcolor(BLUE);
  507.     {
  508.         float vect[3];
  509.         bgnline();
  510.         vect[0] = polygon->polygon[X];
  511.         vect[1] = polygon->polygon[Y];
  512.         vect[2] = polygon->polygon[Z];
  513.         v3f(vect);
  514.         vect[0] += polygon->norm[X];
  515.         vect[1] += polygon->norm[Y];
  516.         vect[2] += polygon->norm[Z];
  517.         v3f(vect);
  518.         endline();
  519.     }
  520. */
  521.     }
  522. }
  523.  
  524.  
  525. build_parts() {
  526.  
  527.     float ct1[100][3], ct2[100][3];
  528.     float norm1[100][3], norm2[100][3];
  529.     Angle a;
  530.     float glsin, glcos;
  531.     int i;
  532.  
  533.     Poly *polygon;
  534.  
  535.     num = 0;
  536.     elbow = new_polygon();
  537.     polygon = elbow;
  538.  
  539.     for (a=0; a<=3600; a += 3600/cres) {
  540.  
  541.     gl_sincos(a, &mycirc[num][Y], &mycirc[num][X]);
  542.     mycirc[num++][Z] = 0.0;
  543.     }
  544.  
  545.     for (i=0; i<num; i++) {
  546.     ct1[i][X] = mycirc[i][X];
  547.     ct1[i][Y] = mycirc[i][Y];
  548.     ct1[i][Z] = mycirc[i][Z];
  549.  
  550.     norm1[i][X] = mycirc[i][X];
  551.     norm1[i][Y] = mycirc[i][Y];
  552.     norm1[i][Z] = mycirc[i][Z];
  553.     }
  554.  
  555.     for (a=joint/bres; a<=joint; a += joint/bres) {
  556.  
  557.     gl_sincos(a, &glsin, &glcos);
  558.  
  559.     for (i=0; i<num; i++) {
  560.  
  561.         ct2[i][X] = mycirc[i][X];
  562.         ct2[i][Y] = (mycirc[i][Y] - elbow_rad) * glcos + elbow_rad;
  563.         ct2[i][Z] = -(mycirc[i][Y]-elbow_rad) * glsin;
  564.  
  565.         norm2[i][X] = mycirc[i][X];
  566.         norm2[i][Y] = mycirc[i][Y] * glcos;
  567.         norm2[i][Z] = -mycirc[i][Y] * glsin;
  568.     }
  569.  
  570.     for (i=0; i<num-1; i++) {
  571.  
  572.         polygon->next = new_polygon();
  573.         polygon = polygon->next;
  574.  
  575.         polygon->polygon = (float *)malloc(sizeof(float) * 3 * 4);
  576.         polygon->norm = (float *)malloc(sizeof(float) * 3 * 4);
  577.         polygon->c = (Colorindex *)malloc(sizeof(float) * 4);
  578.         polygon->n=4;
  579.  
  580.         polygon->polygon[X] = ct1[i][X];
  581.         polygon->polygon[Y] = ct1[i][Y];
  582.         polygon->polygon[Z] = ct1[i][Z];
  583.         polygon->norm[X] = norm1[i][X];
  584.         polygon->norm[Y] = norm1[i][Y];
  585.         polygon->norm[Z] = norm1[i][Z];
  586.  
  587.         polygon->polygon[3+X] = ct2[i][X];
  588.         polygon->polygon[3+Y] = ct2[i][Y];
  589.         polygon->polygon[3+Z] = ct2[i][Z];
  590.         polygon->norm[3+X] = norm2[i][X];
  591.         polygon->norm[3+Y] = norm2[i][Y];
  592.         polygon->norm[3+Z] = norm2[i][Z];
  593.  
  594.         polygon->polygon[6+X] = ct2[i+1][X];
  595.         polygon->polygon[6+Y] = ct2[i+1][Y];
  596.         polygon->polygon[6+Z] = ct2[i+1][Z];
  597.         polygon->norm[6+X] = norm2[i+1][X];
  598.         polygon->norm[6+Y] = norm2[i+1][Y];
  599.         polygon->norm[6+Z] = norm2[i+1][Z];
  600.  
  601.         polygon->polygon[9+X] = ct1[i+1][X];
  602.         polygon->polygon[9+Y] = ct1[i+1][Y];
  603.         polygon->polygon[9+Z] = ct1[i+1][Z];
  604.         polygon->norm[9+X] = norm2[i+1][X];
  605.         polygon->norm[9+Y] = norm2[i+1][Y];
  606.         polygon->norm[9+Z] = norm2[i+1][Z];
  607.     }
  608.  
  609.     for (i=0; i<num; i++) {
  610.         ct1[i][X] = ct2[i][X];
  611.         ct1[i][Y] = ct2[i][Y];
  612.         ct1[i][Z] = ct2[i][Z];
  613.  
  614.         norm1[i][X] = norm2[i][X];
  615.         norm1[i][Y] = norm2[i][Y];
  616.         norm1[i][Z] = norm2[i][Z];
  617.     }
  618.  
  619.     }
  620.  
  621.     double_cylinder = new_polygon();
  622.     polygon = double_cylinder;
  623.  
  624.     gl_sincos(0, &glsin, &glcos);
  625.  
  626.     for (a = 3600/cres; a<=3600; a += 3600/cres) {
  627.  
  628.     polygon->next = new_polygon();
  629.     polygon = polygon->next;
  630.  
  631.     polygon->polygon = (float *)malloc(sizeof(float) * 3 * 4);
  632.     polygon->norm = (float *)malloc(sizeof(float) * 3 * 4);
  633.     polygon->c = (Colorindex *)malloc(sizeof(float) * 4);
  634.     polygon->n=4;
  635.  
  636.     polygon->polygon[X] = glcos;
  637.     polygon->polygon[Y] = glsin;
  638.     polygon->polygon[Z] = -0.1;
  639.     polygon->norm[X] = glcos;
  640.     polygon->norm[Y] = glsin;
  641.     polygon->norm[Z] = 0.0;
  642.  
  643.     polygon->polygon[3+X] = glcos;
  644.     polygon->polygon[3+Y] = glsin;
  645.     polygon->polygon[3+Z] = d_cyl;
  646.     polygon->norm[3+X] = glcos;
  647.     polygon->norm[3+Y] = glsin;
  648.     polygon->norm[3+Z] = 0.0;
  649.  
  650.     gl_sincos(a, &glsin, &glcos);
  651.  
  652.     polygon->polygon[6+X] = glcos;
  653.     polygon->polygon[6+Y] = glsin;
  654.     polygon->polygon[6+Z] = d_cyl;
  655.     polygon->norm[6+X] = glcos;
  656.     polygon->norm[6+Y] = glsin;
  657.     polygon->norm[6+Z] = 0.0;
  658.  
  659.     polygon->polygon[9+X] = glcos;
  660.     polygon->polygon[9+Y] = glsin;
  661.     polygon->polygon[9+Z] = -0.1;
  662.     polygon->norm[9+X] = glcos;
  663.     polygon->norm[9+Y] = glsin;
  664.     polygon->norm[9+Z] = 0.0;
  665.     }
  666.  
  667.     single_cylinder = new_polygon();
  668.     polygon = single_cylinder;
  669.  
  670.     gl_sincos(0, &glsin, &glcos);
  671.  
  672.     for (a = 3600/cres; a<=3600; a += 3600/cres) {
  673.  
  674.     polygon->next = new_polygon();
  675.     polygon = polygon->next;
  676.  
  677.     polygon->polygon = (float *)malloc(sizeof(float) * 3 * 4);
  678.     polygon->norm = (float *)malloc(sizeof(float) * 3 * 4);
  679.     polygon->c = (Colorindex *)malloc(sizeof(float) * 4);
  680.     polygon->n=4;
  681.  
  682.     polygon->polygon[X] = glcos;
  683.     polygon->polygon[Y] = glsin;
  684.     polygon->polygon[Z] = -0.1;
  685.     polygon->norm[X] = glcos;
  686.     polygon->norm[Y] = glsin;
  687.     polygon->norm[Z] = 0.0;
  688.  
  689.     polygon->polygon[3+X] = glcos;
  690.     polygon->polygon[3+Y] = glsin;
  691.     polygon->polygon[3+Z] = s_cyl;
  692.     polygon->norm[3+X] = glcos;
  693.     polygon->norm[3+Y] = glsin;
  694.     polygon->norm[3+Z] = 0.0;
  695.  
  696.     gl_sincos(a, &glsin, &glcos);
  697.  
  698.     polygon->polygon[6+X] = glcos;
  699.     polygon->polygon[6+Y] = glsin;
  700.     polygon->polygon[6+Z] = s_cyl;
  701.     polygon->norm[6+X] = glcos;
  702.     polygon->norm[6+Y] = glsin;
  703.     polygon->norm[6+Z] = 0.0;
  704.  
  705.     polygon->polygon[9+X] = glcos;
  706.     polygon->polygon[9+Y] = glsin;
  707.     polygon->polygon[9+Z] = -0.1;
  708.     polygon->norm[9+X] = glcos;
  709.     polygon->norm[9+Y] = glsin;
  710.     polygon->norm[9+Z] = 0.0;
  711.     }
  712.  
  713. }
  714.  
  715.  
  716. edit_parts() {
  717.  
  718.     float ct1[100][3], ct2[100][3];
  719.     float norm1[100][3], norm2[100][3];
  720.     Angle a;
  721.     float glsin, glcos;
  722.     int i;
  723.  
  724.     Poly *polygon;
  725.  
  726.     polygon = elbow;
  727.  
  728.     for (i=0; i<num; i++) {
  729.     ct1[i][X] = mycirc[i][X];
  730.     ct1[i][Y] = mycirc[i][Y];
  731.     ct1[i][Z] = mycirc[i][Z];
  732.  
  733.     norm1[i][X] = mycirc[i][X];
  734.     norm1[i][Y] = mycirc[i][Y];
  735.     norm1[i][Z] = mycirc[i][Z];
  736.     }
  737.  
  738.     for (a=joint/bres; a<=joint; a += joint/bres) {
  739.  
  740.     gl_sincos(a, &glsin, &glcos);
  741.  
  742.     for (i=0; i<num; i++) {
  743.  
  744.         ct2[i][X] = mycirc[i][X];
  745.         ct2[i][Y] = (mycirc[i][Y] - elbow_rad) * glcos + elbow_rad;
  746.         ct2[i][Z] = -(mycirc[i][Y]-elbow_rad) * glsin;
  747.  
  748.         norm2[i][X] = mycirc[i][X];
  749.         norm2[i][Y] = mycirc[i][Y] * glcos;
  750.         norm2[i][Z] = -mycirc[i][Y] * glsin;
  751.     }
  752.  
  753.     for (i=0; i<num-1; i++) {
  754.  
  755.         polygon = polygon->next;
  756.  
  757.  
  758.         polygon->polygon[X] = ct1[i][X];
  759.         polygon->polygon[Y] = ct1[i][Y];
  760.         polygon->polygon[Z] = ct1[i][Z];
  761.         polygon->norm[X] = norm1[i][X];
  762.         polygon->norm[Y] = norm1[i][Y];
  763.         polygon->norm[Z] = norm1[i][Z];
  764.  
  765.         polygon->polygon[3+X] = ct2[i][X];
  766.         polygon->polygon[3+Y] = ct2[i][Y];
  767.         polygon->polygon[3+Z] = ct2[i][Z];
  768.         polygon->norm[3+X] = norm2[i][X];
  769.         polygon->norm[3+Y] = norm2[i][Y];
  770.         polygon->norm[3+Z] = norm2[i][Z];
  771.  
  772.         polygon->polygon[6+X] = ct2[i+1][X];
  773.         polygon->polygon[6+Y] = ct2[i+1][Y];
  774.         polygon->polygon[6+Z] = ct2[i+1][Z];
  775.         polygon->norm[6+X] = norm2[i+1][X];
  776.         polygon->norm[6+Y] = norm2[i+1][Y];
  777.         polygon->norm[6+Z] = norm2[i+1][Z];
  778.  
  779.         polygon->polygon[9+X] = ct1[i+1][X];
  780.         polygon->polygon[9+Y] = ct1[i+1][Y];
  781.         polygon->polygon[9+Z] = ct1[i+1][Z];
  782.         polygon->norm[9+X] = norm1[i+1][X];
  783.         polygon->norm[9+Y] = norm1[i+1][Y];
  784.         polygon->norm[9+Z] = norm1[i+1][Z];
  785.     }
  786.  
  787.     for (i=0; i<num; i++) {
  788.         ct1[i][X] = ct2[i][X];
  789.         ct1[i][Y] = ct2[i][Y];
  790.         ct1[i][Z] = ct2[i][Z];
  791.  
  792.         norm1[i][X] = norm2[i][X];
  793.         norm1[i][Y] = norm2[i][Y];
  794.         norm1[i][Z] = norm2[i][Z];
  795.     }
  796.  
  797.     }
  798.  
  799.     polygon = double_cylinder;
  800.  
  801.     gl_sincos(0, &glsin, &glcos);
  802.  
  803.     for (a = 3600/cres; a<=3600; a += 3600/cres) {
  804.  
  805.     polygon = polygon->next;
  806.  
  807.     polygon->polygon[X] = glcos;
  808.     polygon->polygon[Y] = glsin;
  809.     polygon->polygon[Z] = -0.1;
  810.     polygon->norm[X] = glcos;
  811.     polygon->norm[Y] = glsin;
  812.     polygon->norm[Z] = 0.0;
  813.  
  814.     polygon->polygon[3+X] = glcos;
  815.     polygon->polygon[3+Y] = glsin;
  816.     polygon->polygon[3+Z] = d_cyl;
  817.     polygon->norm[3+X] = glcos;
  818.     polygon->norm[3+Y] = glsin;
  819.     polygon->norm[3+Z] = 0.0;
  820.  
  821.     gl_sincos(a, &glsin, &glcos);
  822.  
  823.     polygon->polygon[6+X] = glcos;
  824.     polygon->polygon[6+Y] = glsin;
  825.     polygon->polygon[6+Z] = d_cyl;
  826.     polygon->norm[6+X] = glcos;
  827.     polygon->norm[6+Y] = glsin;
  828.     polygon->norm[6+Z] = 0.0;
  829.  
  830.     polygon->polygon[9+X] = glcos;
  831.     polygon->polygon[9+Y] = glsin;
  832.     polygon->polygon[9+Z] = -0.1;
  833.     polygon->norm[9+X] = glcos;
  834.     polygon->norm[9+Y] = glsin;
  835.     polygon->norm[9+Z] = 0.0;
  836.     }
  837.  
  838.  
  839.     polygon = single_cylinder;
  840.  
  841.     gl_sincos(0, &glsin, &glcos);
  842.  
  843.     for (a = 3600/cres; a<=3600; a += 3600/cres) {
  844.  
  845.     polygon = polygon->next;
  846.  
  847.     polygon->polygon[X] = glcos;
  848.     polygon->polygon[Y] = glsin;
  849.     polygon->polygon[Z] = -0.1;
  850.     polygon->norm[X] = glcos;
  851.     polygon->norm[Y] = glsin;
  852.     polygon->norm[Z] = 0.0;
  853.  
  854.     polygon->polygon[3+X] = glcos;
  855.     polygon->polygon[3+Y] = glsin;
  856.     polygon->polygon[3+Z] = s_cyl;
  857.     polygon->norm[3+X] = glcos;
  858.     polygon->norm[3+Y] = glsin;
  859.     polygon->norm[3+Z] = 0.0;
  860.  
  861.     gl_sincos(a, &glsin, &glcos);
  862.  
  863.     polygon->polygon[6+X] = glcos;
  864.     polygon->polygon[6+Y] = glsin;
  865.     polygon->polygon[6+Z] = s_cyl;
  866.     polygon->norm[6+X] = glcos;
  867.     polygon->norm[6+Y] = glsin;
  868.     polygon->norm[6+Z] = 0.0;
  869.  
  870.     polygon->polygon[9+X] = glcos;
  871.     polygon->polygon[9+Y] = glsin;
  872.     polygon->polygon[9+Z] = -0.1;
  873.     polygon->norm[9+X] = glcos;
  874.     polygon->norm[9+Y] = glsin;
  875.     polygon->norm[9+Z] = 0.0;
  876.     }
  877.  
  878. }
  879.  
  880.  
  881.